package com.smartboot.plus.controller;

import com.smartboot.plus.api.R;
import com.smartboot.plus.condition.ConditionGroup;
import com.smartboot.plus.condition.ConditionQ;
import com.smartboot.plus.ignite.cache.MqttAclCache;
import com.smartboot.plus.page.IPage;
import com.smartboot.plus.service.MqttAclService;
import com.smartboot.plus.support.Condition;
import com.smartboot.plus.support.Query;
import com.smartboot.plus.vo.MqttAclCacheVO;
import com.smartboot.plus.wapper.MqttAclWrapper;
import tech.smartboot.feat.cloud.annotation.*;

@Controller("/acl")
public class AclController {

    @Autowired
    private MqttAclService mqttAclService;


    /**
     * 提交
     *
     * @param mqttAclCache
     * @return
     */
    @RequestMapping("/submit")
    public R<Object> submit(MqttAclCache mqttAclCache) {
        return R.status(mqttAclService.submit(mqttAclCache));
    }

    /**
     * 分页
     *
     * @param username
     * @param query
     */
    @RequestMapping("/page")
    public R<IPage<MqttAclCacheVO>> page(@Param("username") String username, Query query) {
        ConditionQ c1 = ConditionQ.like(MqttAclCache::getUsername, username);
        ConditionGroup conditionGroup = new ConditionGroup().add(c1);
        IPage<MqttAclCache> mqttAclCacheIPage = mqttAclService.selectPage(Condition.getPage(query), conditionGroup, MqttAclCache.class);
        IPage<MqttAclCacheVO> mqttAclCacheVOIPage = MqttAclWrapper.build().pageVO(mqttAclCacheIPage);
        return R.data(mqttAclCacheVOIPage);
    }


    /**
     * 删除
     *
     * @param id
     */
    @RequestMapping("/remove/:id")
    public R<Object> remove(@PathParam("id") String id) {
        return R.status(mqttAclService.removeId(id));
    }

}
